package com.vhans.aapi.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.vhans.core.web.controller.BaseController;
import com.vhans.core.web.model.Result;
import com.vhans.core.web.page.TableDataInfo;
import com.vhans.db.model.dto.ConditionDTO;
import com.vhans.db.model.dto.group.GroupDTO;
import com.vhans.db.model.vo.group.GroupInfoVO;
import com.vhans.db.model.vo.group.GroupVO;
import com.vhans.db.service.ICGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 群组Controller控制器
 *
 * @author vhans
 * @date 2023-05-21
 */
@Api(tags = "群组模块")
@RestController
@RequestMapping("/admin/group")
public class GroupController extends BaseController {
    @Autowired
    private ICGroupService groupService;

    /**
     * 查询群组列表
     *
     * @param condition 条件
     * @return {@link GroupVO} 题目列表
     */
    @ApiOperation(value = "查询群组列表")
    @SaCheckPermission("chat:group:list")
    @GetMapping("/list")
    public TableDataInfo list(ConditionDTO condition) {
        startPage();
        List<GroupVO> list = groupService.selectCGroupVOList(condition);
        return getDataTable(list);
    }

    /**
     * 获取群组详细信息
     *
     * @param id 群组id
     * @return {@link Result<GroupInfoVO>} 群组信息
     */
    @ApiOperation(value = "获取群组详细信息")
    @SaCheckPermission("chat:group:query")
    @GetMapping(value = "/info/{id}")
    public Result<GroupInfoVO> getInfo(@PathVariable("id") Integer id) {
        return Result.success(groupService.selectGroupInfoById(id));
    }

    /**
     * 修改群组
     */
    @ApiOperation(value = "修改群组")
    @SaCheckPermission("chat:group:update")
    @PutMapping("/update")
    public Result<?> update(@Validated @RequestBody GroupDTO cGroup) {
        return toAjax(groupService.updateCGroup(cGroup));
    }

    /**
     * 删除群组
     *
     * @param groupDTO 需要删除的群组
     * @return {@link Result<>}
     */
    @ApiOperation(value = "删除群组")
    @SaCheckPermission("chat:group:delete")
    @DeleteMapping("/delete")
    public Result<?> delete(@RequestBody GroupDTO groupDTO) {
        groupService.deleteGroup(groupDTO);
        return Result.success();
    }
}
